<!--
  @description:叫号组件
  @author: lhf
  @time:
-->
<template>
  <div v-show="isShow" class="calling-name-center">
    <div
      :class="['caller-body', msgId === 'ReCall_OneScreen' ? 'voice-right-one' : '', msgContent.waitTreatObject.length < 1 ? 'voice-right-one' : '']"
    >
      <div class="dept-body">{{ info.dept || '' }}{{ '「' + (info.clinic || '') + '」' }}</div>
      <div class="curr-body clearfix over" v-if="msgContent.houZhenAreaJiuZhenVoiceShow == '1'">
        <div class="voice-body clearfix">
          <div class="voice-tips">就诊</div>
          <div class="voice-right">
            <span>{{ msgContent.treatingPatient.rigisterId }}&nbsp;&nbsp;{{ msgContent.treatingPatient.patientName }}</span>
          </div>
        </div>
      </div>
      <div
        class="wait-body clearfix over"
        v-if="msgContent.houZhenAreaHouZhenVoiceShow == '1' && msgId !== 'ReCall_OneScreen' && msgContent.waitTreatObject.length > 0"
      >
        <div class="voice-body clearfix">
          <div class="voice-tips">候诊</div>
          <div class="voice-right">
            <span v-for="(item, index) in msgContent.waitTreatObject" :key="index">{{ item.registerId }}&nbsp;&nbsp;{{ item.patientName }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import mitts from '@/utils/mitt';
export default {
  name: 'msgWin',
  data() {
    return {
      isShow: false,
      msgId: '',
      info: {},
      msgContent: {
        houZhenAreaJiuZhenVoiceShow: 1,
        houZhenAreaHouZhenVoiceShow: 1,
        treatingPatient: {},
        houZhenString: '',
        waitTreatObject: []
      }
    };
  },
  mounted() {
    mitts.on('openMsgWins', this.dealMsgWin);
    mitts.on('closeWins', this.closeMsgWin);
  },
  methods: {
    closeMsgWin() {
      this.isShow = false;
      this.$AndroidSdk.writeLog('收到关闭弹窗---->');
    },
    handlerLimited(arr, max) {
      arr = arr || [];
      return arr.slice(0, max);
    },
    // 处理消息窗口
    dealMsgWin(obj) {
      this.$AndroidSdk.writeLog('收到开启弹窗---->' + JSON.stringify(obj));
      try {
        let msgContent = JSON.parse(obj.msgContent);
        this.msgId = obj.msgId;
        this.msgContent.houZhenAreaJiuZhenVoiceShow = msgContent.houZhenAreaJiuZhenVoiceShow; //就诊是否展示
        this.msgContent.houZhenAreaHouZhenVoiceShow = msgContent.houZhenAreaHouZhenVoiceShow; //候诊是否展示
        this.msgContent.houZhenString = msgContent.houZhenString || ''; // 候诊患者配置内容
        this.msgContent.treatingObject = msgContent.treatingObject || []; // 正在就在配置内容
        let curr = msgContent.treatingPatient || {}; //正在就诊
        let wait = msgContent.waitTreatObject || []; //等候患者
        // 增加判断，如果没有就诊，隐藏窗口
        if (curr.patientName && curr.patientName !== '') {
          this.info = {};
          let vo = msgContent.treatingObject || [];
          for (let i = 0, lens = vo.length; i < lens; i++) {
            this.info[vo[i]['type']] = vo[i]['content'];
          }
          this.msgContent.treatingPatient = curr;
          this.msgContent.waitTreatObject = this.handlerLimited(wait, 6);
          this.isShow = true;
        }
        // 如果不显示就诊患者也不显示候诊患者
        if (this.msgContent.houZhenAreaJiuZhenVoiceShow == '0' && this.msgContent.houZhenAreaHouZhenVoiceShow == '0') {
          this.isShow = false;
        }
        console.log(this.msgContent);
      } catch (e) {
        this.$AndroidSdk.writeLog('dealMsgWin---->' + e.message);
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import '@/assets/styles/wait.scss';
</style>
